package znbkTopicType.resContent;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.webkit.WebView;
import android.widget.LinearLayout;

import com.example.lancooznbk.R;

import lancooControl.Control;
import znbkTopicType.WrapBaseAdapter;
import znbkTestPaperInfor.ZnbkPaperDef;

import static znbkTestPaperBj.activity.NotePaperActivity.mEntityBj;
import static znbkTestPaperRdtz.activity.HeatPointExtensionPaperActivity.mEntityRdtz;
import static znbkTestPaperSc.activity.CollectionPaperActivity.mEntitySc;

/**
 * Created by Administrator on 2018\3\15 0015.
 */

public class ZnbkContentResTplAdapter extends WrapBaseAdapter {

    private LayoutInflater mInflater;
    private Context mContext;
    //当前试题数量
    private int SumItem;
    //当前试题在当前试卷的ID
    private int PaperID;
    private int ModelFrom;//试卷来源


    private ViewHolder holder = null;
    private class ViewHolder{
        LinearLayout mLayoutWebView;

        private ViewHolder(View convertView) {
            mLayoutWebView = (LinearLayout) convertView.findViewById(R.id.layout_WebView);
        }
    }

    /*
   * 获取小题选项信息
   * */
    public ZnbkContentResTplAdapter(Context context, int sumItem, int paperID, int modelFrom) {
        mInflater = LayoutInflater.from(context);
        this.mContext = context;
        this.SumItem = sumItem;
        this.PaperID = paperID;
        this.ModelFrom = modelFrom;
    }

    @Override
    public int getCount() {
        return SumItem;
    }

    @Override
    public Object getItem(int position) {
        return position;
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(final int position, View convertView, ViewGroup parent) {

        if (convertView == null) {
            convertView = mInflater.inflate(R.layout.znbk_adapter_content_tpl_item, null);
            holder = new ViewHolder(convertView);
            convertView.setTag(holder);
        } else {
            holder = (ViewHolder) convertView.getTag();
        }
        /*
        * 获取作文题用户相关信息
        * */
        getQuesInfor();

        /*
        * 显示题干信息
        * */
        showQuesInfor();


        return convertView;
    }


    /*
    * 获取作文题用户相关信息
    * */
    private String ImagePath = "";
    private String ContentBody = "";
    private void  getQuesInfor(){

        if(ModelFrom==ZnbkPaperDef.FROM_HEAT_POINT_EXTENSION){


            /*
            * 图片内容
            * */
                ImagePath = mEntityRdtz.getResFromTK().getImagePath();

        }else if(ModelFrom==ZnbkPaperDef.FROM_COLLECTION){


            /*
            * 图片内容
            * */
                ImagePath = mEntitySc.getResDetail().getImagePath();

        }else if(ModelFrom==ZnbkPaperDef.FROM_NOTE){

            /*
            * 文本内容
            * */
            ImagePath = mEntityBj.getModelTKQue().getImagePath();

        }

    }

    /*
    * 显示界面信息
    * */
    private void showQuesInfor(){
        getContentBody();
    }


    private WebView[] mImageWebView;
    private String[] mImagePath;
    private void getContentBody(){

        int sumOfImage = Control.backSum(ImagePath,"|");
        mImageWebView = new WebView[sumOfImage+1];
        mImagePath = new String[sumOfImage+1];
        for(int i=0;i<sumOfImage+1;i++){
            mImageWebView[i] = new WebView(mContext);
            mImagePath[i] = Control.returnArray(ImagePath,"|",1)[i];
            mImageWebView[i].loadUrl(mImagePath[i]);
            holder.mLayoutWebView.addView(mImageWebView[i]);
        }

    }

}